home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Full / NetObjects Fusion 9 Standard / NOF9_Full_EN.exe / data1.cab / FSI / Ecomm / lib / MainWindow.js < prev    next >
Encoding:
JavaScript  |  2005-11-16  |  12.2 KB  |  295 lines

  1. /** Class EcommEditor
  2. Description : Implement the interface for Ecomm.
  3. Instantiates all window classes (Images, Thumnail, PhotPage)
  4. */
  5.  
  6. /*
  7. @param editedElem, a Ecomm reference
  8. @param document, a object that supperts write/writeln (typically a browser document)
  9. */
  10. function NOF_Ecomm_MainWindow( _editedElement, _document, _name ) {
  11.   this.__proto__ = NOF_Ecomm_MainWindow.prototype;
  12.   this.SUPER( _editedElement, _document, _name );
  13.  
  14.   this.tempEditedElement = _editedElement;
  15.   this.tempDocument = _document;
  16.   this.defaultName = "ECOMMERCE_EDITOR";
  17. }
  18. NOF_Ecomm_MainWindow.inherits ( NOF.HTML.TabbedMenuEditorWindow );
  19. function NOF_Ecomm_MainWindow_ProtoBuilder() {
  20.   var method = NOF_Ecomm_MainWindow.prototype;
  21.  
  22.   //event handlers
  23.   method.onInit = function onInit(){
  24.     //timesXXX += "Startup: " + ( (new Date()).getTime() - startTimeOD )+ "\n";
  25.     //timesXXX += "loading: " + (new Date()).getTime() + "\n";
  26. log.info("before loading editedElement");        
  27.     this.editedElement.load();
  28. log.info("after loading editedElement");
  29.     //timesXXX += "loaded: " + (new Date()).getTime() + "\n";
  30.     var store = this.loadStore();
  31. log.info("after loading store");
  32.     this.setOverridingResource(store);
  33. log.info("loading NOF.ecomm.products.MainWindow ");
  34.     this.productsEditor   = new NOF.ecomm.products.MainWindow   ( this.editedElement, this.document);
  35. log.info("loading NOF.ecomm.listpage.MainWindow ");
  36.     this.listPageEditor   = new NOF.ecomm.listpage.MainWindow   ( this.editedElement, this.document);
  37. log.info("loading NOF.ecomm.detailpage.MainWindow ");        
  38.     this.detailPageEditor = new NOF.ecomm.detailpage.MainWindow ( this.editedElement, this.document);
  39. log.info("loading NOF.ecomm.StoreEditor ");
  40.     this.storeEditor      = new NOF.ecomm.StoreEditor      ( this.editedElement, this.document);
  41. log.info("NOF.ecomm.StoreEditor loaded");
  42.     this.addChild( this.productsEditor );
  43.     this.addChild( this.listPageEditor );
  44.     this.addChild( this.detailPageEditor );
  45.     this.addChild( this.storeEditor );
  46.  
  47.     this.productsEditor.addListener( this.listPageEditor );
  48.     this.storeEditor.addListener(this.productsEditor);
  49.     this.storeEditor.addListener(this);
  50.  
  51.     //initialize main tabbed menu
  52.     var tabbedMenu = new NOF.UI.TabbedMenu("ecMainMenu", "NOF.EC_MainMenu", this);
  53.     // for compatibility (should be rewritten to use HTMLDoc)
  54.     tabbedMenu.setDocument (this.document);
  55. log.info("adding NOF.EcommTabMenuItem ");
  56.     tabbedMenu.addItem (new NOF.EcommTabMenuItem (this.productsEditor.getName(), this.getResourceProperty("products.title"), this.getApp()) );
  57.     tabbedMenu.addItem (new NOF.EcommTabMenuItem (this.listPageEditor.getName(), this.getResourceProperty("listPage.title"), this.getApp()) );
  58.     tabbedMenu.addItem (new NOF.EcommTabMenuItem (this.detailPageEditor.getName(), this.getResourceProperty("detailPage.title"), this.getApp()) );
  59.     tabbedMenu.addItem (new NOF.EcommTabMenuItem (this.storeEditor.getName(), this.getResourceProperty("store.title"), this.getApp()) );
  60.     tabbedMenu.addListener( this ); //adds it to all menu items
  61.     this.setMenu ( tabbedMenu );
  62.     NOF.addVariable ("EC_MainMenu", tabbedMenu);
  63. log.info("menuitems added");
  64.     this.productsEditor.init();
  65.         
  66.     this.listPageEditor.init();
  67.     this.detailPageEditor.init();
  68. log.info("editors init finshed");        
  69.     this.super_onInit();    //this is implemented in base class and simply notifies the listners that this window has intitialised
  70.   }
  71.  
  72.   method.onLoad = function onLoad() {
  73.     this.setTitle (this.getResourceProperty("products.dialog.title"));
  74.     var width  = this.getResourceProperty('mainwindow.width') || 630;
  75.     var height = this.getResourceProperty('mainwindow.height') || 470;
  76.     
  77.     this.setSize(width, height);
  78.     //timesXXX += "initializing: " + (new Date()).getTime() + "\n";
  79.  
  80.     this.doc.initialize(this);
  81.  
  82.     //timesXXX += "initialized: " + ( new Date() ).getTime() + "\n";
  83.     //timesXXX += "Total: " + ( (new Date()).getTime() - startTimeOD )+ "\n";
  84.     //alert ( timesXXX );
  85.  
  86.     var tabbedMenu = this.getMenu();
  87.     tabbedMenu.selectItem( tabbedMenu.getItem( this.productsEditor.getName()) );
  88.  
  89.     this.productsEditor.onLoad();
  90.     this.listPageEditor.onLoad();
  91.     this.detailPageEditor.onLoad();
  92.     this.storeEditor.onLoad();
  93.     this.productsEditor.show();
  94.     //this.detailPageEditor.show();
  95.   }
  96.  
  97.   method.onDone = function onDone() {
  98.     this.onSave();
  99.     window.close();
  100.   }
  101.  
  102.   method.onSave = function onSave() {
  103.     this.productsEditor.onSave();
  104.     this.listPageEditor.onSave();
  105.     this.detailPageEditor.onSave();    
  106.     this.storeEditor.onSave();
  107.     this.editedElement.save( true );
  108.     
  109.     //TODO: tie it to the actual editors status!!
  110.     NOF.App.getFSIApp().IntArg = 3; //means that both index & display are modified
  111.   }
  112.  
  113.   method.onUnload = function onUnload() {
  114.     this.detailPageEditor.onUnload();
  115.     this.listPageEditor.onUnload();
  116.     this.editedElement.prepareForPublish();
  117.     NOF.App.getFSIApp().IntArg = 3; //means that both index & display are modified
  118.     // once the ecomm editor dialog loaded it should never return cancel and
  119.     // as such disappear from the page
  120.     NOF.App.cancelScript(false);
  121.   }
  122.  
  123.   method.onSaveProfile = function onSaveProfile() {
  124.     result = window.showModalDialog("dialogs/profiles/managerDlg.html", [NOF, this, this.getEditedElement()], "status:no;help:no;border:thin;dialogWidth:280px;dialogHeight:260px;center:yes;scroll:no;");
  125.   }
  126.  
  127.   /*
  128.     * onUpdateData
  129.     * @param evt an event of NOF.WindowEvent.DATAUPDATE_TO_CTRL or NOF.WindowEvent.DATAUPDATE_FROM_CTRL type
  130.   */
  131.   method.onUpdateData = function onUpdateData( direction ){
  132.     this.listPageEditor.doDataUpdate( direction);
  133.     this.detailPageEditor.doDataUpdate( direction );
  134.   }
  135.  
  136.   method.super_actionPerformed = method.actionPerformed;
  137.   /** actionPerformed
  138.       @param evt name.
  139.   */
  140.   method.actionPerformed = function actionPerformed( evt ) {
  141.     if ( evt instanceof NOF.StoreEvent ){      
  142.       if (evt.getID() == "CURRENCY_CHANGED") {
  143.         this.updatePricing(this.storeEditor.store);
  144.       }
  145.       else if (evt.getID() == "WEIGHT_CHANGED") {
  146.         this.updateWeightSystem(this.storeEditor.store);
  147.       }
  148.       else if (evt.getID() == "IMGUPLOAD_CHANGED") {
  149.         this.forceUploadImages();
  150.       }
  151.       else {
  152.         //var store = this.loadStore();
  153.         var oldResPath = this.getApp().getOverridingResourcePath();
  154.         this.setOverridingResource(this.storeEditor.store);
  155.         var newResPath = this.getApp().getOverridingResourcePath();
  156.         if (oldResPath != newResPath) {
  157.           this.doc.initialize(this);
  158.           this.listPageEditor.displayItemsEditor.updateLabels();
  159.           this.detailPageEditor.displayItemsEditor.updateLabels();
  160.         }
  161.         var listPageData = this.editedElement.getListPage();
  162.         var detailPageData = this.editedElement.getDetailPage();
  163.         if (this.storeEditor.store.type == NOF.Store.NO_STORE) {
  164.           //this.editedElement.setLabelDefaults();
  165.           this.doc.cleanElementValue('listpage.purchaseoptions.displaybuy');
  166.           this.doc.cleanElementValue('listpage.purchaseoptions.displayadd');
  167.           this.doc.cleanElementValue('detailpage.purchaseoptions.displaybuy');
  168.           this.doc.cleanElementValue('detailpage.purchaseoptions.displayadd');
  169.         }
  170.         else {
  171.           var enableButtons = evt.getSource();
  172.           if (enableButtons) {
  173.             this.doc.setElementValue('listpage.purchaseoptions.displaybuy', 'yes');
  174.             this.doc.setElementValue('listpage.purchaseoptions.displayadd', 'yes');
  175.             this.doc.setElementValue('detailpage.purchaseoptions.displaybuy', 'yes');
  176.             this.doc.setElementValue('detailpage.purchaseoptions.displayadd', 'yes');
  177.           }
  178.         }
  179.         this.updatePricing(this.storeEditor.store, true);
  180.         this.updateWeightSystem(this.storeEditor.store, true);
  181.       }
  182.     }
  183.     else if ( !(evt instanceof NOF.ProductEvent) ) //ignore ProductEvent ones. this would be better handled via addXXXListener methods for specific events
  184.       return this.super_actionPerformed( evt );
  185.   }
  186.  
  187.   method.forceUploadImages = function forceUploadImages() {
  188.     this.editedElement.forceUploadImages();
  189.   }
  190.  
  191.   method.updateWeightSystem = function updateWeightSystem (store, isStoreChange) {
  192.     var listPageData = this.editedElement.getListPage();
  193.     var dItemsEx = listPageData.getDisplayedItemsEx();
  194.     var detailPageData = this.editedElement.getDetailPage();
  195.     var dItemsEx2 = detailPageData.getDisplayedItemsEx();
  196.  
  197.     if (isStoreChange &&
  198.         !dItemsEx["weight"].isPostfixIncluded() && !dItemsEx["weight"].isPrefixIncluded() &&
  199.         !dItemsEx2["weight"].isPostfixIncluded() && !dItemsEx2["weight"].isPrefixIncluded()) {
  200.  
  201.       var loc = this.getResourceProperty("store.defaultWeightSystemLocation");
  202.       if (store.type != NOF.Store.NO_STORE) {
  203.         var engine = store.getStoreEngine(NOF.App.getDefaultLocale());
  204.         loc = engine.getDefaultWeightSystemLabelLocation ();
  205.       }
  206.       if (loc == "prefix") {
  207.         dItemsEx["weight"].setPrefixIncluded (true);
  208.         dItemsEx2["weight"].setPrefixIncluded (true);
  209.       }
  210.       else if (loc == "postfix") {
  211.         dItemsEx["weight"].setPostfixIncluded (true);
  212.         dItemsEx2["weight"].setPostfixIncluded (true);
  213.       }
  214.     }
  215.  
  216.     this.setPrePostLabel (dItemsEx["weight"], store.weightSystemLabel, store.weightSystem);
  217.     this.setPrePostLabel (dItemsEx2["weight"], store.weightSystemLabel, store.weightSystem);
  218.   }
  219.  
  220.   method.updatePricing = function updatePricing (store, isStoreChange) {
  221.     var listPageData = this.editedElement.getListPage();
  222.     var dItemsEx = listPageData.getDisplayedItemsEx();
  223.     var detailPageData = this.editedElement.getDetailPage();
  224.     var dItemsEx2 = detailPageData.getDisplayedItemsEx();
  225.  
  226.     if (isStoreChange &&
  227.         !dItemsEx["price"].isPostfixIncluded() && !dItemsEx["price"].isPrefixIncluded() &&
  228.         !dItemsEx2["price"].isPostfixIncluded() && !dItemsEx2["price"].isPrefixIncluded()) {
  229.  
  230.       var loc = this.getResourceProperty("store.defaultCurrencyLabelLocation");
  231.       if (store.type != NOF.Store.NO_STORE) {
  232.         var engine = store.getStoreEngine(NOF.App.getDefaultLocale());
  233.         loc = engine.getDefaultCurrencyLabelLocation ();
  234.       }
  235.       if (loc == "prefix") {
  236.         dItemsEx["price"].setPrefixIncluded (true);
  237.         dItemsEx2["price"].setPrefixIncluded (true);
  238.       }
  239.       else if (loc == "postfix") {
  240.         dItemsEx["price"].setPostfixIncluded (true);
  241.         dItemsEx2["price"].setPostfixIncluded (true);
  242.       }
  243.     }
  244.  
  245.     this.setPrePostLabel (dItemsEx["price"], store.currencyLabel, store.currency);
  246.     this.setPrePostLabel (dItemsEx2["price"], store.currencyLabel, store.currency);
  247.     var items = ["retailprice","shipping","tax"];
  248.     for (var i=0; i<3; i++) {
  249.       this.setPrePostLabel (dItemsEx[items[i]], store.currencyLabel, store.currency);
  250.       this.setPrePostLabel (dItemsEx2[items[i]], store.currencyLabel, store.currency);
  251.     }
  252.     
  253.   }
  254.  
  255.   method.setPrePostLabel = function setPrePostLabel(dItemsElem, label, item) {
  256.     var _label = "";
  257.     if (label != null && label.length > 0) {
  258.       _label = label;
  259.     }
  260.     else if (item != null && item.length > 0) {
  261.       _label = this.getResourceProperty("fmtdlg.prepost.label." + item);
  262.       if (_label == null || _label.length == 0)
  263.         _label = item;
  264.     }
  265.     else
  266.       _label = "";
  267.     if (dItemsElem.isPostfixIncluded())
  268.       dItemsElem.setPostfix(_label);
  269.     if (dItemsElem.isPrefixIncluded())
  270.       dItemsElem.setPrefix(_label);
  271.   }
  272.  
  273.   method.loadStore = function loadStore () {
  274.     var storeId = this.editedElement.getStoreTypeId();
  275.     var store = new NOF.Store (storeId);
  276.     store.load();
  277.     return store;
  278.   }
  279.  
  280.   method.setOverridingResource = function setOverridingResource (store) {
  281.     if (store.type != NOF.Store.NO_STORE) {
  282.         //alert(" " + store.type + " != " + NOF.Store.NO_STORE);
  283.         var rPath = store.getStoreEngine(NOF.App.getDefaultLocale()).getLabelsPath();
  284.         //alert(rPath);
  285.       this.getApp().setOverridingResourcePath (rPath);
  286.     } else {
  287.         //alert(" " + store.type + " = " + NOF.Store.NO_STORE);
  288.       this.getApp().clearOverridingResource();
  289.     }    
  290.   }
  291.  
  292. }
  293.  
  294. NOF_Ecomm_MainWindow_ProtoBuilder();
  295.